import fire
from pathlib import Path

from funboost.core.cli.funboost_fire import BoosterFire, env_dict
from funboost.core.cli.discovery_boosters import BoosterDiscovery

import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from app.funcs import alert_wechat

from utils.tools import logger
from app.module.contoller.uploadfile_controller import uploadController
from app.module.contoller.genqa_controller import genQaController
from app.module.contoller.wechat_controller import wechatController
from app.module.contoller.chatat_controller import chatatController


app = FastAPI()


# class TaskStatusModel(BaseModel):
# task_id: str


# @app.get("/alert_wechat/")
# def alert_wechat_api(wx_name="exlo", message: str = "这是一个测试告警"):
#     """接口直接最大阻塞120s直到任务执行完成"""
#     async_result = alert_wechat.push(wx_name, message)
#     logger.debug(f"返回taskid给前端： [{async_result.task_id}]")
#     model = TaskStatusModel(task_id=async_result.task_id)
#     return model


project_root_path = Path(__file__).absolute().parent
env_dict["project_root_path"] = project_root_path
BoosterDiscovery(
    project_root_path, booster_dirs=[], max_depth=1, py_file_re_str=None
).auto_discovery()  # 这个最好放到main里面,如果要扫描自身文件夹,没写正则排除文件本身,会无限懵逼死循环导入
fire.Fire(
    BoosterFire,
)

app.include_router(uploadController, prefix="/upload", tags=["上传文件"])
app.include_router(genQaController, prefix="/genqa", tags=["生成问答"])
app.include_router(wechatController, prefix="/alert", tags=["告警推送"])
app.include_router(chatatController, prefix="/chatat", tags=["一键生成Q&A数据集"])

if __name__ == "__main__":

    uvicorn.run(
        app="main:app",
        host="0.0.0.0",
        port=8088,
    )
